package com.business.action.wechat;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.business.service.weixin.WeixinReplyService;
import com.business.wechat.bean.WeixinReplyBean;

import net.sf.rose.jdbc.PageBean;
import net.sf.rose.jdbc.dao.BeanDAO;
import net.sf.rose.jdbc.service.Service;

@Controller
@RequestMapping("/weixin/reply")
public class WechatReplyAction {

	@Autowired
	private WeixinReplyService replyService;

	/**
	 * 查询回复信息列表
	 */
	@ResponseBody
	@RequestMapping("/page.do")
	public PageBean page(HttpServletRequest request, Service service) {
		return replyService.page(request, new BeanDAO(service));
	}

	/**
	 * 根据编号查询回复信息
	 */
	@ResponseBody
	@RequestMapping("/load.do")
	public WeixinReplyBean load(HttpServletRequest request, Service service, String id) {
		return replyService.load(new BeanDAO(service), id);
	}

	/**
	 * 保存回复信息
	 */
	@ResponseBody
	@RequestMapping("/save.do")
	public PageBean save(HttpServletRequest request, Service service, WeixinReplyBean bean) {
		PageBean res = new PageBean();
    	int i = replyService.save(new BeanDAO(service), bean);
		if (i > 0) {
			res.setMessage("保存回复信息成功！");
		} else {
			res.setSuccess(false);
			res.setMessage("保存回复信息失败！");
		}
		return res;
	}

	/**
	 * 删除
	 */
	@ResponseBody
	@RequestMapping("/delete.do")
	public PageBean delete(HttpServletRequest request, Service service, String id) {
		PageBean res = new PageBean();
    	int i = replyService.delete(new BeanDAO(service), id);
		if (i > 0) {
			res.setMessage("删除回复信息成功！");
		} else {
			res.setSuccess(false);
			res.setMessage("删除回复信息失败！");
		}
		return res;
	}
}
